package com.dev.security.tools.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.dev.security.config.dao.BaseRepository;
import com.dev.security.tools.beans.Dictionary;
import com.dev.security.tools.beans.DictionaryId;

/**
 * @author 飘渺青衣
 * @see
 */
public interface DictionaryRepository extends BaseRepository<Dictionary, DictionaryId> {

	@Query("select dic from Dictionary dic where parent=?1 order by sort")
	public List<Dictionary> findAll(String parent);
	
	@Modifying
	@Query("delete from Dictionary where parent=?1 and value in ?2")
	public int delete(String parent, String[] values);
	
	@Modifying
	@Query("delete from Dictionary where parent=?1")
	public int delete(String parent);
	
	@Modifying
	@Query("delete from Dictionary where parent in ?1")
	public int delete(String[] parents);
	
	@Query("select count(*) from Dictionary where parent=?1 and value=?2")
	public int count(String parent, String value);
	
}
